<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>set</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h1>学校信息</h1>
        <h2>学校名称：{{name}}</h2>
        <h2>学校地址：{{address}}</h2>
        <hr/>
        <h1>学生信息</h1>
        <button @click="addSex">添加一个性别属性，默认位男</button>
        <h2>学生名称：{{student.name}}</h2>
        <h2 v-if="student.sex">学生性别：{{student.sex}}</h2>
        <h2>学生年龄：真实{{student.age.rAge}}，对外{{student.age.sAge}}</h2>
        <h2>朋友们</h2>
        <ul>
            <li v-for="(f,index) in student.friends" :key="index">
            {{f.name}}-{{f.age}}
        </li>
        </ul>
    </div>
</body>
<!--   JS   -->
    <script>
    const vm = new Vue({
        el:'#root',
        data:{
            name:'swpu',
            address:'成都',
            student:{
                name:'Evan',
                age:{
                    rAge:21,
                    sAge:18
                },
                friends:[
                    {name:'jerry',age:15},
                    {name:'tom',age:25}
                ]
            }
        },
        methods: {
            addSex(){
                // Vue.set(this.student,'sex','男')
                this.$set(this.student,'sex','男')
            }
        },
    })
    </script>
</html>